package cn.stylefeng.guns.modular.util;

/**
 * 加密
 */
public class MD5EncryptionPwdUtil {

    //开头
    private final static String prefix = "ief";
    //结尾
    private final static String suffix = "itr";
    //中间
    private final static String middle = "iry";
    //中间的插入顺序是密码的长度和6的模作为插入位置
    private final static Integer indexModel = 6;

    /**
     * 加密
     *
     * @param inputPwd
     * @return
     */
    public static String encryptionMd5(String inputPwd) {
        int length = inputPwd.length();
        for (int i = 0; i < length; i++) {

            Integer inputIndex = inputPwd.length() % indexModel;
            //加密规则 加密的字符串由 prefix+ pwd长度与indexModel取模,作为插入节点,然后把middle插入中间+suffix,之后进行加密
            String encryptionPwd = prefix + inputPwd.substring(0, inputIndex) + middle + inputPwd.substring(inputIndex) + suffix;
            inputPwd = Utils_MD5.GetMD5Code(encryptionPwd);
        }
        return Utils_MD5.GetMD5Code(inputPwd);
    }


    public static void main(String[] args) {
        String pwd = "4584535gdg.@#$#2";
        String s = encryptionMd5(pwd);
        System.out.println("加密字符串=" + s);
    }

}
